package com.oa.modules.approvalsec1.controller;

import java.util.*;

import com.oa.common.utils.AppUtils;
import com.oa.modules.approvalsec1.dao.DataDocumentDao;
import com.oa.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.oa.modules.approvalsec1.entity.DataDocumentEntity;
import com.oa.modules.approvalsec1.service.DataDocumentService;
import com.oa.common.utils.PageUtils;
import com.oa.common.utils.R;



/**
 *
 *
 * @author jiangwei
 * @email 785297226@qq.com
 * @date 2021-04-25 14:39:34
 */
@RestController
@RequestMapping("data/document")
@Api(tags =  "共享中心相关接口")
public class DataDocumentController extends AbstractController {

    @Autowired
    private DataDocumentService dataDocumentService;
    @Autowired
    private DataDocumentDao dataDocumentDao;
    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = dataDocumentService.queryPage(params);
        return R.ok().put("page", page);
    }

    @PostMapping("/wxlist")
    @ApiOperation(value = "查询")
    public R wxlist(@RequestBody Map<String, Object> reqParams){
        List<DataDocumentEntity> dataDocumentList = dataDocumentService.queryDataDocumentByName(reqParams);
        return R.ok().put("success",dataDocumentList);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "信息")
    public R info(@PathVariable("id") String id){
		DataDocumentEntity dataDocument = dataDocumentService.getById(id);
        return R.ok().put("dataDocument", dataDocument);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public R save(@RequestBody DataDocumentEntity dataDocument){
        dataDocument.setId(AppUtils.getUUID());
        dataDocument.setCreateDate(new Date());
        dataDocument.setCreateOper("1");
		dataDocumentService.save(dataDocument);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public R update(@RequestBody DataDocumentEntity dataDocument){
        dataDocument.setUpdateDate(new Date());
        dataDocument.setUpdateOper(getUserId().toString());
		dataDocumentService.updateById(dataDocument);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public R delete(@RequestBody String[] ids){
		dataDocumentService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    @PostMapping("/updateType")
    @ApiOperation(value = "修改办理状态")
    public R update(@RequestBody HashMap<String,Object> params){
       dataDocumentService.updateType(params);
        return R.ok();
    }
}
